/**
 * 数据格式
 */
// const res = {
//     errorCode: "0",
//     errorMessage: "处理成功",
//     success: true,
//     value: {
//         lastPoolDraw: {
//             lotteryDrawNum: "24037",
//             lotteryDrawResult: "9 1 0 7 6",
//             lotteryDrawTime: "2024-02-06",
//             lotteryGameName: "排列5",
//             lotteryGameNum: "350133",
//             poolBalanceAfterdraw: "24,139,395.10",
//         },
//         list: [
//             {
//                 lotteryDrawNum: "24037",
//                 lotteryDrawResult: "9 1 0 7 6",
//                 lotteryDrawTime: "2024-02-06",
//                 lotteryGameName: "排列5",
//                 lotteryGameNum: "350133",
//                 poolBalanceAfterdraw: "24,139,395.10",
//             }
//         ],
//         pageNo: 2,
//         pageSize: 30,
//         pages: 228,
//         total: 6839,
//     }
// }
const _fetch = (pageNo = 1, gameNo) => {
    return new Promise(async (resolve, reject) => {
        fetch('https://webapi.sporttery.cn/gateway/lottery/getHistoryPageListV1.qry?gameNo=' + gameNo + '&provinceId=0&pageSize=100&isVerify=1&pageNo=' + pageNo).then(res => res.json()).then(async res => {
            if (res.success) {
                const data = {
                    lastPoolDraw: {
                        lotteryDrawNum: res.value.lastPoolDraw.lotteryDrawNum,
                        lotteryDrawResult: res.value.lastPoolDraw.lotteryDrawResult,
                        lotteryDrawTime: res.value.lastPoolDraw.lotteryDrawTime,
                        lotteryGameName: res.value.lastPoolDraw.lotteryGameName,
                        lotteryGameNum: res.value.lastPoolDraw.lotteryGameNum,
                        poolBalanceAfterdraw: res.value.lastPoolDraw.poolBalanceAfterdraw,
                    },
                    list: res.value.list.map(item => ({
                        lotteryDrawNum: item.lotteryDrawNum,
                        lotteryDrawResult: item.lotteryDrawResult,
                        lotteryDrawTime: item.lotteryDrawTime,
                        lotteryGameName: item.lotteryGameName,
                        lotteryGameNum: item.lotteryGameNum,
                        poolBalanceAfterdraw: item.poolBalanceAfterdraw,
                    })),
                    pageNo: res.value.pageNo,
                    pageSize: res.value.pageSize,
                    pages: res.value.pages,
                    total: res.value.total,
                }
                resolve(data)
            } else {
                reject(res.errorMessage)
            }
        }).catch(error => {
            reject(error)
        })
    })
}

const fetchSortFive = (pageNo) => {
    const gameNo = '350133'
    return _fetch(pageNo, gameNo)
}

const fetchSevenStar = (pageNo) => {
    const gameNo = '04'
    return _fetch(pageNo, gameNo)
}

export {
    fetchSortFive,
    fetchSevenStar,
}